﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mamnontuoitho7.AppCode;
using System.Data;
using System.Text.RegularExpressions;

namespace mamnontuoitho7.backend
{
    public partial class ClipList : System.Web.UI.Page
    {
        private VideoClip _videoClip = new VideoClip();
        private Product _product = new Product();
        protected General _general = new General();
        protected DataTable _dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check Role Admin
            if (Session["memberID"].ToString() != "" && (ConstantClass.permissionArticle).IndexOf(Session["role"].ToString() + ",") != -1)
            {

                if (Request.QueryString["productID"] != null && Request.QueryString["visible"] != null)
                {
                    string temp = Request.QueryString["productID"].ToString();
                    Match match = Regex.Match(temp, @"([0-9])$", RegexOptions.IgnoreCase);

                    if (temp.Length <= 4 && match.Success)
                    {
                        try
                        {
                            string _ProductID = temp;
                            string _Status = Request.QueryString["visible"].ToString();
                            _product.ChangeProductStatus(_ProductID, _Status);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Response.Redirect(ConstantClass._errorAdminPage);
                        }
                        Response.Redirect("ClipList.aspx");
                    }
                }

                try
                {
                    if (Request.QueryString["ProductIDDelete"] != null)
                    {
                        string _ProductID = Request.QueryString["ProductIDDelete"].ToString();
                        _product.ProductDelete(_ProductID);

                    }
                    if (!IsPostBack)
                    {
                        ddlAmountRecord.Items.Insert(0, new ListItem("50 Clip Mới Nhất", "50"));
                        ddlAmountRecord.Items.Insert(1, new ListItem("Tất Cả Clip", "0"));
                    }
                    _dt = _videoClip.GetVideo("admin", ddlAmountRecord.SelectedValue);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Response.Redirect(ConstantClass._errorAdminPage);
                }
            }
            else
            {
                Response.Redirect(ConstantClass._errorLoginPage);
            }
        }

        protected void ddlAmountRecord_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                _dt = _videoClip.GetVideo("admin", ddlAmountRecord.SelectedValue);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Response.Redirect(ConstantClass._errorAdminPage);
            }
        }
    }
}